<?php
/*********************************************
  CPG Dragonfly™ CMS
  ********************************************
  Copyright © 2004-2005 by CPG-Nuke Dev Team
  http://www.dragonflycms.com

  Dragonfly is released under the terms and conditions
  of the GNU GPL version 2 or any later version
Encoding test: n-array summation ∑ latin ae w/ acute ǽ
********************************************************/
if (!defined('CPG_NUKE')) { exit; }

// useflags is set in configuration
global $currentlang, $MAIN_CFG;

if (!Dragonfly::getKernel()->L10N->multilingual) {
	return trigger_error('Multilingual is off', E_USER_WARNING);
}

$qs = array();
parse_str($_SERVER['QUERY_STRING'], $qs);
unset($qs['newlang']);
$qs['newlang'] = '';
$qs = '?'.htmlspecialchars(str_replace('=&','&',http_build_query($qs)));

if ($MAIN_CFG->global->useflags) {
	foreach (Dragonfly::getKernel()->L10N->getActiveList() as $lng)
	{
		$image = 'images/l10n/'.$lng['value'].'.png';
		$content .= '<a href="'.$qs.$lng['value'].'">';
		// akamu fix for broken images if lang doesn't have flag
		if (file_exists($image)){
			$content .= "<img src=\"{$image}\" align=\"middle\" alt=\"{$lng['title']}\" title=\"{$lng['title']}\" style=\"border:0; padding:3px\"/>";
		} else {
			$content .= $lng['title'];
		}
		$content .= '</a> ';
	}
} else {
	$content = '<form title="This option will change the language of this website" action="" method="get"><div>
	<select name="newlanguage" onchange="top.location.href=\''.BASEHREF.'\'+this.options[this.selectedIndex].value">';
	foreach (Dragonfly::getKernel()->L10N->getActiveList() as $lng)
	{
		$content .= '<option value="'.$qs.$lng['value'].'"';
		if ($lng['value']==$currentlang) $content .= ' selected="selected"';
		$content .= '>'.$lng['title']."</option>\n";
	}
	$content .= '</select></div></form>';
}
